import * as jwt from 'jsonwebtoken';
export class JwtUtils {
  // 生成
  static get(content: any, key: any, options: object = {}) {
    return new Promise((resolve, reject) => {
      jwt.sign(content, key, { ...options }, (err, token) => {
        if (err) {
          reject(err);
        } else {
          resolve(token);
        }
      });
    });
  }

  // 合法性判断与解析
  static check(token: string, key: any, options: object = {}) {
    return new Promise((resolve, reject) => {
      jwt.verify(token, key, { ...options }, (err, payload) => {
        if (err) {
          reject(err);
        } else {
          resolve(payload);
        }
      });
    });
  }
}
